package com.wgchao.identityrightsmanagement.domain.organization.model;

import com.wgchao.identityrightsmanagement.infrastructure.exception.ObjectDisabledException;
import com.wgchao.identityrightsmanagement.infrastructure.exception.ObjectNotMatchException;
import org.springframework.stereotype.Component;

/**
 * @ClassName: AssignDepartmentToAccountService
 * @author: wgchao
 * @createTime: 2020/6/7 6:56 PM
 * @Description: 为账户分配部门
 */
@Component
public class AssignDepartmentToAccountService {

    public Account assignDepartmentToAccount(Account account, Department department){
        account.normalException();
        department.normalException();
        if(!account.getAgencyCode().equals(department.getAgencyCode())){
            throw new ObjectNotMatchException("部门与账户不属于同一个机构");
        }
        account.setDepartmentCode(department.getCode());

        return account;
    }
}
